
#ifndef __LINK_SERIALCLIENT_H__
#define __LINK_SERIALCLIENT_H__
#include "MQTTClient.h"
#include "base/LinkBase.h"
#include <map>



/*
    连接接口实现类： Mqtt 连接
    
*/

namespace controller
{
    class LinkMqttClient : public LinkBase
    {
    private:
        MQTTClient fd = nullptr;
        MQTTClient_deliveryToken last_token;
        std::string url;
        std::string deviceid;
        std::string key;
        static void *LinkMqttThreadMonitor(void *pParam);
        pthread_t thread = 0;
        bool m_isThreadRunning = false;
        std::map<std::string, std::string> _param;

    public:
        LinkMqttClient(/* args */);
        ~LinkMqttClient();
        bool isThreadRunning();
        MQTTClient client();
        bool release();
        std::map<std::string, std::string> params();

        // 读写接口
        bool open(std::map<std::string, std::string>) override;          // 打开 url, deviceid,key,sub1,sub2,sub3,...
        bool close() override;                                           // 关闭
        int write(char *data, int len, const char *arg = NULL) override; // 写,data = {"topic":"xxxx","payload":"hex array"},    len = strlen(data)
        // int read(char *dataout, int len) override;              // 读,dataout = {"topic":"xxxx","payload":"hex array"}, len = strlen(dataout)

        // 状态
        bool is_open() override;     // 设备是否打开
        std::string name() override; // 设备名称
        std::string info() override; // 设备信息
    };
};

#endif // ! __LINK_TCPCLIENT_H__
